﻿using System.Linq;
using StreetPacMan.Server.Facade;

namespace StreetPacMan.Server.Tests
{
    public static class ServerFacadeTestExtensions
    {
        public static CreateGameResult CreateGameX(this IServerFacade source, string gameName)
        {
            return source.CreateGame(new CreateGameParameters(gameName));
        }

        public static JoinGameResult JoinGameX(this IServerFacade source, string gameName, string playerName, PlayerRole role)
        {
            return source.JoinGame(new JoinGameParameters(gameName, playerName, role));
        }

        public static GetAllEventsResults GetAllEventsX(this IServerFacade source, string gameName)
        {
            var gameId = source.GetAllGames().Games.Where(x => x.Name == gameName).First().Id;
            return source.GetAllEvents(new GetAllEventsParameters(gameId));
        }
        public static GetGameStateResult GetGameStateForX(this IServerFacade source, int playerId)
        {
            return source.GetGameState(new GetGameStateParameters(playerId));
        }
        public static GetGameStateResult GetGameStateAsObvserverX(this IServerFacade source, string gameName)
        {
            var firstEntityId = source.GetAllGames().Games.Where(x => x.Name == gameName).First().Players.First().EntityId;
            return source.GetGameState(new GetGameStateParameters(firstEntityId));
        }
    }
}